<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取一个key所映射的服务器信息</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="memcached.getresultmessage.html">« Memcached::getResultMessage</a></li>
      <li style="float: right;"><a href="memcached.getserverlist.html">Memcached::getServerList »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.memcached.html">Memcached</a></li>
    <li>获取一个key所映射的服务器信息</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="memcached.getserverbykey" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcached::getServerByKey</h1>
  <p class="verinfo">(PECL memcached &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::getServerByKey</span> &mdash; <span class="dc-title">获取一个key所映射的服务器信息</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcached.getserverbykey-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Memcached::getServerByKey</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$server_key</code></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>Memcached::getServerByKey()</strong></span>返回<code class="parameter">server_key</code>所映射的服务器, 
   <span class="function"><strong>Memcached::*ByKey()</strong></span>系列方法的中的<code class="parameter">server_key</code>参数, 实际上就是用来获取
   操作的服务器的.(译注: 可以这样理解, *ByKey系列函数首先调用<span class="function"><strong>Memcached::getServerByKey()</strong></span>获取服务器, 
   然后在此服务器上进行操作.)
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-memcached.getserverbykey-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">server_key</code></dt>

     <dd>

      <p class="para">
       本键名用于识别储存和读取值的服务器。没有将实际的键名散列到具体的项目，而是在决定与哪一个 memcached 服务器通信时将其散列为服务器键名。这使得关联的项目在单一的服务上被组合起来以提高多重操作的效率。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcached.getserverbykey-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
   如需要则使用 <span class="methodname"><a href="memcached.getresultcode.html" class="methodname">Memcached::getResultCode()</a></span>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcached.getserverbykey-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4400">
    <p><strong>示例 #1 <span class="function"><strong>Memcached::getServerByKey()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addServers</span><span style="color: #007700">(array(<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'mem1.domain.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">40</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'mem2.domain.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">40</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;array(</span><span style="color: #DD0000">'mem3.domain.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11211</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">),<br />));<br /><br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setOption</span><span style="color: #007700">(</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">OPT_LIBKETAMA_COMPATIBLE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getServerByKey</span><span style="color: #007700">(</span><span style="color: #DD0000">'user'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getServerByKey</span><span style="color: #007700">(</span><span style="color: #DD0000">'log'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getServerByKey</span><span style="color: #007700">(</span><span style="color: #DD0000">'ip'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array(3) {
  [&quot;host&quot;]=&gt;
  string(15) &quot;mem3.domain.com&quot;
  [&quot;port&quot;]=&gt;
  int(11211)
  [&quot;weight&quot;]=&gt;
  int(20)
}
array(3) {
  [&quot;host&quot;]=&gt;
  string(15) &quot;mem2.domain.com&quot;
  [&quot;port&quot;]=&gt;
  int(11211)
  [&quot;weight&quot;]=&gt;
  int(40)
}
array(3) {
  [&quot;host&quot;]=&gt;
  string(15) &quot;mem2.domain.com&quot;
  [&quot;port&quot;]=&gt;
  int(11211)
  [&quot;weight&quot;]=&gt;
  int(40)
}
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div></div></div></body></html>